package net.aetherial.context.grounding.estimators;

import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;

/**
 * A testing estimator that cheats by returning the coded values as the estimate. Used for testing the system.
 */

public class CheatingEstimator extends Estimator
{
	private List<Double> filchedScores;
	
	/**
	 * Constructor.
	 */
	
	public CheatingEstimator ()
	{
		filchedScores = new ArrayList<Double> ();
		
		String path = System.getProperty ("xml.chats.path");

		if (path == null)
			path = "/Users/cjkarr/Desktop/chats_ls/";

		try 
		{

			File f = new File (path);

			if (f.isDirectory ())
			{
				DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ();
				factory.setIgnoringElementContentWhitespace (true);
				
				DocumentBuilder builder = factory.newDocumentBuilder ();

				// File[] children = f.listFiles ();

				// for (File child: children)
				// {
				
				File child = new File ("/Users/cjkarr/Desktop/chats_ls/convo1_LS.xml");

				
					if (child.getAbsolutePath().endsWith (".xml"))
					{
						Document d = builder.parse (child);
						
						NodeList list = d.getElementsByTagName ("turn");
						
						for (int i = 0; i < list.getLength (); i++)
						{
							Element turn = (Element) list.item (i);

							filchedScores.add (Double.parseDouble (turn.getAttribute ("score")));
						}
					}
				// }
			}
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}

	/**
	 * Returns "CheatingEstimator".
	 * 
	 * @see net.aetherial.context.grounding.estimators.Estimator#getName()
	 */
	
	public String getName() 
	{
		return "CheatingEstimator";
	}

	/**
	 * @see net.aetherial.context.grounding.estimators.Estimator#estimate(java.lang.String, java.lang.String, double)
	 */
	
	public double estimate(String sender, String contribution, double score) 
	{
		double s = filchedScores.get (0);
		
		filchedScores.remove (0);
		
		return s;
	}
}
